//
// Created by hjie on 23-7-22.
//
#include <cstring>
#include <string>
#include "./../base/link.h"

void OddEventList()
{
    LinkList list = {};
    int length = 11;
    NoSortLinkList(list, length);
    PrintLinkList(list);

    LinkNode * tail = list.tail_node;
    LinkNode * tail_1 = tail;
    LinkNode * ptr  = list.head_node;
    LinkNode * prev = list.head_node;

    bool even = false;
    while(ptr && ptr != tail_1)
    {
        if (even)
        {
            prev->next_node = ptr->next_node;
            ptr->next_node = nullptr;
            tail->next_node = ptr;
            tail = ptr;
            ptr = prev->next_node;
            even = false;
            continue;
        }
        else
        {
            even = true;
        }
        prev = ptr;
        ptr  = ptr->next_node;
    }
    if (even)
    {
        prev->next_node = tail_1->next_node;
        tail->next_node = tail_1;
        tail_1->next_node = nullptr;
    }
    PrintLinkList(list);
}
int main(int argc, const char * argv[])
{

    OddEventList();
    return EXIT_SUCCESS;
}